<template>
	<view style="width: 710rpx;margin: 0 auto;background-color: white;padding: 40rpx 0;">
		<view class="product-intro" id="past3">
			<!-- <view class="title">{{ $t(`产品介绍`) }}</view> -->
			<view class="conter">
				<!-- #ifndef APP-PLUS -->
				<parser :html="description" ref="article" :tag-style="tagStyle"></parser>
				<!-- #endif -->
				<!-- #ifdef APP-PLUS -->
				<view class="description" v-html="description"></view>
				<!-- #endif -->
			</view>
			<view class="" style="width: 100%;margin: 20rpx auto 0 auto;text-align: center;border: 1px solid gray;height: 90rpx;line-height: 90rpx;background-color: #f7e58d;font-size: 50rpx;font-weight: 400;">
				{{sku}}
			</view>
		</view>
	</view>
</template>

<script>
	import { mapGetters } from 'vuex'
	import parser from '@/components/jyf-parser/jyf-parser';
	import { getProductDetail } from '@/api/store.js';
	
	
	export default {
		components: {
			parser,
		},
		name: 'ordergoodsv2',
		computed: mapGetters(['uid']),
		props: {
			
			cartInfo: {
				type: Array,
				default: function() {
					return [];
				}
			},
			
			shipping_type: {
				type: Number,
				default: -1,
			},
			
			is_confirm: {
				type: Boolean,
				default: false,
			},
			
		},
		data() {
			return {
				product_id:0,
				sku:'',
				description: '',
				tagStyle: {
					img: 'width:100%;display:block;',
					table: 'width:100%',
					video: 'width:100%;height:100%;'
				},
			};
		},
		watch: {
			cartInfo: function(nVal, oVal) {
				console.log(nVal)
				let that = this
				nVal.forEach((item, index) => {
					that.product_id = item.product_id;
					that.sku = item.productInfo.attrInfo.suk
					that.getGoodsDetails();
				})
			}
		},
		onLoad(options) {
			let that = this;
			that.getGoodsDetails();
		},
		mounted() {
			let num = 0
			this.$nextTick(() => {
				this.cartInfo.forEach((item, index) => {
					num += item.cart_num
				})
				this.$set(this, 'totalNmu', num)
			})

		},
		methods: {
			/**
			 * 获取产品详情
			 *
			 */
			getGoodsDetails: function () {
				let that = this;
				// uni.showLoading({
				// 	title: '加载中',
				// 	mask: true
				// });
				getProductDetail(that.product_id)
					.then((res) => {
						// uni.hideLoading();
						let storeInfo = res.data.storeInfo;
						let good_list = res.data.good_list || [];
						let count = Math.ceil(good_list.length / 6);
						let goodArray = new Array();
						for (let i = 0; i < count; i++) {
							let list = good_list.slice(i * 6, i * 6 + 6);
							if (list.length)
								goodArray.push({
									list: list
								});
						}
						that.$set(that, 'storeInfo', storeInfo);
						that.$set(that, 'description', storeInfo.description);
						// if (this.description) {
						// 	this.description = this.description.replace(/<img/gi, '<img style="max-width:100%;height:auto;float:left;display:block" ');
						// 	this.description = this.description.replace(/<video/gi, '<video style="width:100%;height:300px;display:block" ');
						// }
					})
					.catch((err) => {
						// uni.hideLoading();
						//状态异常返回上级页面
						// return that.$util.Tips(
						// 	{
						// 		title: err.toString()
						// 	},
						// 	{
						// 		tab: 3,
						// 		url: 1
						// 	}
						// );
					});
			}
		}
	}
</script>

<style scoped lang="scss">
	
	.conter {
		display: block;
	}
	
	.conter img {
		display: block;
	}
</style>
